  //index.js
//获取应用实例
const app = getApp();

Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    isHide: false,
    personal:[]
  },

  //事件处理函数
  goInfos: function(event) {
    wx.navigateTo({
      url:"../infos/infos"
    });
  },
  ceshi: function (event) {
    wx.navigateTo({
      url: "../ceshi/ceshi"
    });
  },
  customer: function (event) {
    wx.navigateTo({
      url: "../customer/customer"
    });
  },
  goOrder: function (event) {
    if (event.currentTarget.id == "payw"){
      wx.navigateTo({
        url: "../order/order?od=0",
      });
    }
  },
  search:function(){
    wx.navigateTo({
      url: "../search/search"
    });
  },
  cash:function(){
    wx.navigateTo({
      url: "../commission/cash/cash"
    });
  },
  count: function () {
    wx.navigateTo({
      url: "../commission/count/count"
    });
  },
  team: function () {
    wx.navigateTo({
      url: "../team/team"
    });
  },
  balance: function () {
    wx.navigateTo({
      url: "../balance/balance"
    });
  },
  commission: function () {
    wx.navigateTo({
      url: "../commission/commission"
    });
  },
  detail: function () {
    wx.navigateTo({
      url: "../detail/detail"
    });
  },
  pay: function () {
    wx.navigateTo({
      url: "../order/pay/pay"
    });
  },
  address: function () {
    wx.navigateTo({
      url: "../address/address"
    });
  },
  fill: function () {
    wx.navigateTo({
      url: "../address/fill/fill"
    });
  },
  phone: function () {
    wx.navigateTo({
      url: "../address/phone/phone"
    });
  },
  collection: function () {
    wx.navigateTo({
      url: "../collection/collection"
    });
  },
  alipay: function () {
    wx.navigateTo({
      url: "../alipay/alipay"
    });
  },
  coupon: function () {
    wx.navigateTo({
      url: "../coupon/coupon"
    });
  },
  allorder: function () {
    wx.navigateTo({
      url: "../order/allorder/allorder"
    });
  },
  onLoad: function () {
    var that = this;
    var rooturl = app.globalData.url;//请求数据接口地址

    // 查看是否授权
    wx.getSetting({
      success: function (res) {
        if (res.authSetting['scope.userInfo']) {
          wx.getUserInfo({
            success: function (res) {
              // 用户已经授权过,不需要显示授权页面,所以不需要改变 isHide 的值
              wx.login({
                success: function (res) {
                  // 获取到用户的 openid
                  wx.request({
                    url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + app.globalData.appid + '&secret=' + app.globalData.secret + '&js_code=' + res.code + '&grant_type=authorization_code',
                    success: function (res) {
                      // console.log(res);
                      //请求数据 secret.php
                      wx.request({//个人中心
                        url: rooturl + 'member_personal.php',
                        method: 'POST',
                        header: {
                          "Content-Type": "application/json"
                        },
                        success: function (res) {
                          var personal = res.data.result.data;
                          that.setData({
                            personal: personal
                          })
                        }
                      });

                    }
                  });
                }
              });
            }
          });
        } else {
          // 用户没有授权 改变 isHide 的值，显示授权页面
          that.setData({
            isHide: true
          });
        }
      }
    });
  },

  bindGetUserInfo: function (e) {
    if (e.detail.userInfo) {
      //用户按了允许授权按钮
      var that = this;
      // 获取到用户的信息了，打印到控制台上看下
      // console.log("用户的信息如下：");
      // console.log(e.detail.userInfo);
      //授权成功后,通过改变 isHide 的值，让实现页面显示出来，把授权页面隐藏起来
      that.setData({
        isHide: false
      });

    } else {
      //用户按了拒绝按钮
      wx.showModal({
        title: '警告',
        content: '您点击了拒绝授权，将无法进入小程序，请授权之后再进入!!!',
        showCancel: false,
        confirmText: '返回授权',
        success: function (res) {
          // 用户没有授权成功，不需要改变 isHide 的值
        }
      });
    }
  }


})




